package com.prj.ufdm.webflux.api;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.prj.ufdm.webflux.bpo.DeviceHandler;
import com.prj.ufdm.webflux.proxy.DynamicDeviceDefaultHandlerProxy;

@RestController
@RequestMapping("/proxy")
public class ProxyApi implements ApplicationContextAware {
	
	private ApplicationContext applicationContext;
	
//    @Autowired
//    @Qualifier("deviceHandlerRouter")
//    private DeviceHandlerRouter deviceHandlerRouter;
	
	@GetMapping("/test")
    public String getTest(String name) throws Exception {
		
		DeviceHandler deviceHandler = DynamicDeviceDefaultHandlerProxy.newMapperProxy(DeviceHandler.class.getName(),this.applicationContext);
		
		return deviceHandler.requestHttpResult(name);
		
//        DeviceHandler deviceHandlerFeignImpl = deviceHandlerRouter.getHandler(1, null);
//
//        DeviceHandler deviceHandlerUrlImpl = deviceHandlerRouter.getHandler(2, null);
        
//        return "123";
        
	}
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext = applicationContext;
	}

}
